﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace HJ_SQL_ToTable
{
    /// <summary>
    ///     SQL文本分割器
    /// </summary>
    public class SQLSplitor
    {
        /// <summary>
        ///     将sql文本中所有的CREATE TABLE提示出来
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static List<string> Split(string sql, string rule)
        {
            List<string> sqls = new List<string>();
            MatchCollection mts_;
            try
            {
                mts_ = Regex.Matches(sql, rule);

                for (int i = 0; i < mts_.Count; i++)
                {
                    Match mt = mts_[i];
                    var value = mt.Groups[0].Value;
                    sqls.Add(value);
                }
            }
            catch (Exception ex)
            {
                sqls.Clear();
            }

            return sqls;
        }
    }
}
